<template>
  <el-card class="form-card">
    <h2>用户注册</h2>
    <el-form :model="form" @submit.prevent="onRegister" label-width="80px">
      <el-form-item label="用户名">
        <el-input v-model="form.username" required />
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="form.password" type="password" required />
      </el-form-item>
      <el-form-item label="姓名">
        <el-input v-model="form.name" required />
      </el-form-item>
      <el-form-item label="邮箱">
        <el-input v-model="form.email" required />
      </el-form-item>
      <el-form-item label="手机号">
        <el-input v-model="form.phone" required />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" native-type="submit">注册</el-button>
      </el-form-item>
    </el-form>
    <el-alert v-if="msg" type="success" :closable="false" show-icon>{{ msg }}</el-alert>
  </el-card>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { userApi } from '../api/user'

const form = ref({ username: '', password: '', name: '', email: '', phone: '' })
const msg = ref('')

const onRegister = async () => {
  await userApi.register(form.value)
  msg.value = '注册成功！'
}
</script>
<style scoped>
.form-card {
  max-width: 400px;
  margin: 40px auto;
}
</style> 